//
//  MSTextFiled.m
//  testMasory
//
//  Created by xiangbo on 2018/9/20.
//  Copyright © 2018年 xiangbo. All rights reserved.
//

#import "MSTextField.h"

@implementation MSTextField

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#E5E5E5"];
        [self addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self);
            make.bottom.equalTo(self);
            make.height.mas_equalTo(0.5);
        }];
        self.font = [UIFont systemFontOfSize:14.f];
    }
    return self;
}

- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
    CGRect iconRect = [super leftViewRectForBounds:bounds];
    iconRect.origin.x += 15; //像右边偏15
    return iconRect;
}

//  重写占位符的x值
- (CGRect)placeholderRectForBounds:(CGRect)bounds{
    CGRect placeholderRect = [super placeholderRectForBounds:bounds];
    CGFloat leftView = self.isHideLeftView?18:54;
    placeholderRect.origin.x = leftView;
    return placeholderRect;
}

//UITextField 文字与输入框的距离
- (CGRect)textRectForBounds:(CGRect)bounds {
    CGFloat leftView = self.isHideLeftView?18:54;
    return CGRectInset(bounds, leftView, 0);
}

//控制文本的位置
- (CGRect)editingRectForBounds:(CGRect)bounds{
    CGFloat leftView = self.isHideLeftView?18:54;
    return CGRectInset(bounds, leftView, 0);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
